using System;
using System.Collections.Generic;
using Rapier.Kodachi.Shared;
using iTunesLib;
using System.Drawing;

namespace Rapier.Kodachi.iTunes
{
    public class iTunesPlugin : Plugin
    {
        #region Data Members
        private Bitmap[] stars = new Bitmap[6];
        #endregion

        #region Protected Members
        public iTunesApp iTunes = null;
        #endregion

        #region Constructor
        public iTunesPlugin(Host host) : base(host)
        {
            stars[0] = Properties.Resources._0star;
            stars[1] = Properties.Resources._1star;
            stars[2] = Properties.Resources._2star;
            stars[3] = Properties.Resources._3star;
            stars[4] = Properties.Resources._4star;
            stars[5] = Properties.Resources._5star;
        }
        #endregion

        #region Overrides
        public override string Author
        {
            get { return "El Guapo"; }
        }

        public override string Url
        {
            get { return "http://www.rapiersoftware.com"; }
        }

        public override bool HasSettings
        {
            get { return false; }
        }

        public override void UpdateDatabase()
        {
            // Add items
            Item ratingOne = new Item(this, "Rating", "1 Star", "Rate Current Track 1 Star");
            ratingOne.GetImage = delegate() { return stars[1]; };
            ratingOne.IndirectOnly = true;
            ratingOne.Properties["iTunesRating"] = true;
            Host.AddItem(ratingOne);

            Item ratingTwo = new Item(this, "Rating", "2 Star", "Rate Current Track 2 Stars");
            ratingTwo.IndirectOnly = true;
            ratingTwo.GetImage = delegate() { return stars[2]; };
            ratingTwo.Properties["iTunesRating"] = true;
            Host.AddItem(ratingTwo);

            Item ratingThree = new Item(this, "Rating", "3 Star", "Rate Current Track 3 Stars");
            ratingThree.IndirectOnly = true;
            ratingThree.GetImage = delegate() { return stars[3]; };
            ratingThree.Properties["iTunesRating"] = true;
            Host.AddItem(ratingThree);

            Item ratingFour = new Item(this, "Rating", "4 Star", "Rate Current Track 4 Stars");
            ratingFour.IndirectOnly = true;
            ratingFour.GetImage = delegate() { return stars[4]; };
            ratingFour.Properties["iTunesRating"] = true;
            Host.AddItem(ratingFour);

            Item ratingFive = new Item(this, "Rating", "5 Star", "Rate Current Track 5 Stars");
            ratingFive.IndirectOnly = true;
            ratingFive.GetImage = delegate() { return stars[5]; };
            ratingFive.Properties["iTunesRating"] = true;
            Host.AddItem(ratingFive);

            Item ratingClear = new Item(this, "Rating", "Clear", "Clear Rating");
            ratingClear.IndirectOnly = true;
            ratingClear.GetImage = delegate() { return stars[0]; };
            ratingClear.Properties["iTunesRating"] = true;
            Host.AddItem(ratingClear);

            // Add actions
            Host.AddAction(new Actions.PlayPause(this));
            Host.AddAction(new Actions.TrackNext(this));
            Host.AddAction(new Actions.TrackPrevious(this));
            Host.AddAction(new Actions.VolumeSet(this));
            Host.AddAction(new Actions.VolumeMute(this));
            Host.AddAction(new Actions.Stop(this));
            Host.AddAction(new Actions.TrackInfo(this));
            Host.AddAction(new Actions.RateTrack(this));
        }
        
        public override void ExtendItem(Item item)
        {
            if (item.Name.Equals("iTunes", StringComparison.InvariantCultureIgnoreCase))
            {
                item.Properties["iTunes"] = true;
            }
        }
        #endregion
    }
}
